$.post('trans.php',{'dest':'php/log.php','action':'check_coder'},function(iscoder){
	if(iscoder)
		showCoder();
});

$('#coder').click(function(){
	showCoder();
});
function showCoder(){
	page=function(page){	//num为每页显示的数目
		$.post('trans.php',{'dest':'php/bloglist.php','num':8,'page':page},function(data){
			$('#article_detail').fadeOut(function(){
				$('#comments').html('');
				$('#list').html(data);
			})
			$('#article_detail').fadeIn();
		});
		
	}
	page(1);
	showDetail=function(aid,current_page){	//文章类容、评论
		/**************/
		/*****文章*****/
		/**************/
$('#article_detail').fadeTo('fast',0.01,function(){
		$.post('trans.php',{
				'dest':'php/article.php',
				'aid':aid,
				'page':current_page
			},function(data){
						$('#list').html(data);
					});
		/**************/
		/*****评论*****/
		/**************/
		$.post('trans.php',{
			'dest':'php/comments.php',					//获取回复列表
			'action':'getReply',
			'aid':aid
			},function(data){
				$('#comments').html(data);
				$('#article_detail').fadeTo('fast',1);

			$('#reply_submit').click(function(){	//提交对文章的回复
				content=$('#reply').val();
				if(content){
					$.post('trans.php',{
						'dest':'php/comments.php',
						'action':'reply',
						'aid':aid,
						'content':content
						},function(bool){
							if(data){
/*							$.post('php/comments.php',{
	可能有错							'action':'getreply',
								'aid':aid
								},function(data){
									$('#comments').html(data);
							});
*/							
							showDetail(aid,current_page);
							}
					});
						
				}
			});
			replyTo=function(aid,floor){		//点击楼回复按钮
				var sp=5,p=-100,op=0;
				var dt=setInterval(function(){
					p+=sp;
					op+=0.1;
					if(p>5||op>=1)
						clearInterval(dt);
					$('#reply_to_box').css('right',p+'px');
					$('#reply_to_box').fadeTo(10,op);
					
				},20);

				$('#reply_to_submit').html('回<br>复<br>'+floor+'<br>楼');
				$('#reply_to_cancel').click(function(){
					$('#reply_to_box').fadeOut(function(){
						$('#reply_to_box').css('right','-100px');
					});
				});
				$('#reply_to_submit').click(function(){		//对楼回复，提交
					var content=$('#reply_to_content').val();
					if(content){
						$.post('trans.php',{
							'dest':'php/comments.php',
							'action':'replyTo',
							'content':content,
							'aid':aid,
							'floor':floor
						},function(bool){
							if(bool){
									showDetail(aid,current_page);		/************/
	//						$.post('php/comments.php',{					/****可能****/
	//							'action':'getreply',					/****    ****/
	//							'aid':aid								/****有错****/
	//							},function(data){						/************/
	//								$('#comments').html(data);			/************/
	//						});
							}
						});
					}
				});
			}
		});
});//<----------------------------------点击showDetail时 fade out------评论获得之后fade in 
	}
	/*show detail end*/

	/* coder side bar */
	$.post('trans.php',{
		'dest':'php/codersidebar.php',
		'action':'getSideBar',
		'latestCommentsNum':10,
		'highestClickNum':10
	},function(data){
		var ev='var side='+data;
		
		eval(ev);
		cat=side.category;
		lc=side.latestComments;
		hc=side.highestClick;
		$('#category').html(cat);
		$('#latestComments').html(lc);
		$('#highestClick').html(hc);
	});
	/* side bar END*/
}	//----------------------------------------showCoder() END--------------------
